const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const phoneNumberReg = number => {
  // 手机号码验证
  var phoeeReg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  return phoeeReg.test(number);
}

const isBlank = value => {
  return value == null || value == '' || value == undefined;
}

const nameReg = name => {
  // 中文，英文大小写; 正则需要以//开头
  var nameReg = /^[a-zA-Z\u4e00-\u9fa5]{2,20}$/
  return nameReg.test(name);
}

const commonInfoModel = content => {
  wx.showModal({
    title: '提示',
    content: isBlank(content) ? '异常' : content,
    showCancel: false
  })
}

const commonShowLoading = x => {
  wx.showLoading({
    title: '加载中....',
  })
}

/**暴露需要被外界调用的方法 */
module.exports = {
  formatTime: formatTime,
  phoneNumberReg: phoneNumberReg,
  isBlank: isBlank,
  nameReg: nameReg,
  commonInfoModel: commonInfoModel,
  commonShowLoading: commonShowLoading
}

